dofile (getScriptPath() .. "\\..\\lib\\orders.lua")
dofile (getScriptPath() .. "\\..\\lib\\actions.lua")

pos = orders:GetPosition(nil, true)

for sec_code, p in pairs(lib:GetInstrumentPosition()) do
	if not pos[sec_code] then
		instrument = lib:GetInstrument(sec_code)
		if instrument then
			instrument.qty__ = math.abs(p)
			
			if p > 0 then
				instrument.side__ = "S"
			elseif p < 0 then
				instrument.side__ = "B"
			end
			
			orders:SendLimit(instrument)
		end
	end
end

message("QUIT")
actions:Exit()

processor:stop(0)
